/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.helpdesk.entidades;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Manuel
 */


@Entity
@Table(name = "hd_tickets")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "HdTickets.findAll", query = "SELECT h FROM HdTickets h"),
    @NamedQuery(name = "HdTickets.findByCodTicket", query = "SELECT h FROM HdTickets h WHERE h.codTicket = :codTicket"),
    @NamedQuery(name = "HdTickets.findByDescTicket", query = "SELECT h FROM HdTickets h WHERE h.descTicket = :descTicket"),
    @NamedQuery(name = "HdTickets.findByFecResolucion", query = "SELECT h FROM HdTickets h WHERE h.fecResolucion = :fecResolucion"),
    @NamedQuery(name = "HdTickets.findByFecResolucionReal", query = "SELECT h FROM HdTickets h WHERE h.fecResolucionReal = :fecResolucionReal"),
    @NamedQuery(name = "HdTickets.findByFecRegistro", query = "SELECT h FROM HdTickets h WHERE h.fecRegistro = :fecRegistro"),
    @NamedQuery(name = "HdTickets.CountTicketsByUser", query = "SELECT COUNT(h) FROM HdTickets h WHERE h.codUsuario = :codUsuario AND h.codClasiBaja.codClasiBaja = :codClasiBaja"),
    @NamedQuery(name = "HdTickets.ShowTicketsBySolicitante", query = "SELECT h FROM HdTickets h WHERE h.codUsuario.codUsuario = :codUsuario"),
    @NamedQuery(name = "HdTickets.ShowTicketsByUser", query = "SELECT h FROM HdTickets h WHERE h.codUsuario = :codUsuario AND h.codClasiBaja.codClasiBaja = :codClasiBaja"),
    @NamedQuery(name = "HdTickets.ShowTicketsByAsesores", query = "SELECT h FROM HdTickets h WHERE h.codAsesor.codAsesor = :codAsesor"),
    @NamedQuery(name = "HdTickets.ShowTicketsByEstado", query = "SELECT h FROM HdTickets h WHERE h.codEstado.codEstado = :codEstado"),
    @NamedQuery(name = "HdTickets.ShowTicketsJefe", query = "SELECT h FROM HdTickets h WHERE h.codEstado.codEstado = :codEstado AND h.codJefe = :codJefe"),
    @NamedQuery(name = "HdTickets.ShowTicketsUserCerrados", query = "SELECT h FROM HdTickets h WHERE h.codEstado.codEstado = :codEstado AND h.codUsuario = :codUsuario"),
    @NamedQuery(name = "HdTickets.ShowTicketsPendientes", query = "SELECT h FROM HdTickets h WHERE h.codUsuario = :codUsuario AND h.codEstado.codEstado NOT IN (6,7)"),
    @NamedQuery(name = "HdTickets.ShowTicketsBycodJefeAndcodEstado", query = "SELECT h FROM HdTickets h WHERE h.codJefe = :codJefe AND (h.codEstado.codEstado = :codEstado1 OR h.codEstado.codEstado = :codEstado2)"),
})
    
public class HdTickets implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy= GenerationType.TABLE, generator="TICKETS")
    @TableGenerator(name="TICKETS", 
                    table="tbsequence",
                    pkColumnName="seq_name",
                    valueColumnName="seq_count")
    @Column(name = "COD_TICKET", nullable=false)
    @Basic(optional = false)
    @NotNull
    private Integer codTicket;
    @Size(max = 200)
    @Column(name = "TITULO_TICKET")
    private String tituloTicket;
    @Column(name = "DESC_TICKET")
    private String descTicket;
    @Column(name = "FEC_RESOLUCION")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecResolucion;
    @Column(name = "FEC_RESOLUCION_REAL")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecResolucionReal;
    @Basic(optional = false)
    @NotNull
    @Column(name = "FEC_REGISTRO")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecRegistro;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "codTicket")
    private List<HdDetalleTicket> hdDetalleTicketList;
    @JoinColumn(name = "COD_USUARIO", referencedColumnName = "COD_USUARIO")
    @ManyToOne
    private HdUsuarios codUsuario;
    @JoinColumn(name = "COD_ASESOR", referencedColumnName = "COD_ASESOR")
    @ManyToOne
    private HdAsesor codAsesor;
    @JoinColumn(name = "COD_ESTADO", referencedColumnName = "COD_ESTADO")
    @ManyToOne
    private HdEstados codEstado;
    @JoinColumn(name = "COD_CLASI_BAJA", referencedColumnName = "COD_CLASI_BAJA")
    @ManyToOne
    private HdClasifiBaja codClasiBaja;
    @JoinColumn(name = "COD_JEFE", referencedColumnName = "COD_TECNICO")
    @ManyToOne
    private HdTecnicos codJefe;
    @Column(name = "FEC_CANALIZADO")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecCanalizado;
    
    @Basic
    @Column(name="COD_JEFE", insertable = false, updatable = false)
    private Integer idJefe;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "codTicket")
    private List<HdHistorial> hdHistorialList;

    public HdTickets() {
    }

    public HdTickets(Integer codTicket) {
        this.codTicket = codTicket;
    }

    public HdTickets(Integer codTicket, Date fecRegistro) {
        this.codTicket = codTicket;
        this.fecRegistro = fecRegistro;
    }

    public Integer getCodTicket() {
        return codTicket;
    }

    public void setCodTicket(Integer codTicket) {
        this.codTicket = codTicket;
    }

    public String getDescTicket() {
        return descTicket;
    }

    public void setDescTicket(String descTicket) {
        this.descTicket = descTicket;
    }

    public Date getFecResolucion() {
        return fecResolucion;
    }

    public void setFecResolucion(Date fecResolucion) {
        this.fecResolucion = fecResolucion;
    }

    public Date getFecResolucionReal() {
        return fecResolucionReal;
    }

    public void setFecResolucionReal(Date fecResolucionReal) {
        this.fecResolucionReal = fecResolucionReal;
    }

    public Date getFecRegistro() {
        return fecRegistro;
    }

    public void setFecRegistro(Date fecRegistro) {
        this.fecRegistro = fecRegistro;
    }
    
   public HdTecnicos getCodJefe() {
        return codJefe;
    }

    public void setCodJefe(HdTecnicos codJefe) {
        this.codJefe = codJefe;
    }

    public Integer getIdJefe() {
        return idJefe;
    }

    public void setIdJefe(Integer idJefe) {
        this.idJefe = idJefe;
    }

    public Date getFecCanalizado() {
        return fecCanalizado;
    }

    public void setFecCanalizado(Date fecCanalizado) {
        this.fecCanalizado = fecCanalizado;
    }
    

    @XmlTransient
    public List<HdDetalleTicket> getHdDetalleTicketList() {
        return hdDetalleTicketList;
    }

    public void setHdDetalleTicketList(List<HdDetalleTicket> hdDetalleTicketList) {
        this.hdDetalleTicketList = hdDetalleTicketList;
    }

    public HdUsuarios getCodUsuario() {
        return codUsuario;
    }

    public void setCodUsuario(HdUsuarios codUsuario) {
        this.codUsuario = codUsuario;
    }
    
    public HdAsesor getCodAsesor() {
        return codAsesor;
    }

    public void setCodAsesor(HdAsesor codAsesor) {
        this.codAsesor = codAsesor;
    }

    public HdEstados getCodEstado() {
        return codEstado;
    }

    public void setCodEstado(HdEstados codEstado) {
        this.codEstado = codEstado;
    }

    public HdClasifiBaja getCodClasiBaja() {
        return codClasiBaja;
    }

    public void setCodClasiBaja(HdClasifiBaja codClasiBaja) {
        this.codClasiBaja = codClasiBaja;
    }

    @XmlTransient
    public List<HdHistorial> getHdHistorialList() {
        return hdHistorialList;
    }

    public void setHdHistorialList(List<HdHistorial> hdHistorialList) {
        this.hdHistorialList = hdHistorialList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (codTicket != null ? codTicket.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof HdTickets)) {
            return false;
        }
        HdTickets other = (HdTickets) object;
        if ((this.codTicket == null && other.codTicket != null) || (this.codTicket != null && !this.codTicket.equals(other.codTicket))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
       // return "com.helpdesk.entidades.HdTickets[ codTicket=" + codTicket + " ]";
        return "Ticket: "+descTicket;
    }

    /**
     * @return the tituloTicket
     */
    public String getTituloTicket() {
        return tituloTicket;
    }

    /**
     * @param tituloTicket the tituloTicket to set
     */
    public void setTituloTicket(String tituloTicket) {
        this.tituloTicket = tituloTicket;
    }
    
    
}
